<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增</title>
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:inline="javascript">
        $(function () {
            $.get("/players/clubs",function (data) {
                for(club of data){
                    if(club.cid == [[${players.cid}]]){
                        $("select").append("<option value='"+club.cid+"' selected>"+club.cname+"</option>");
                    }else{
                        $("select").append("<option value='"+club.cid+"'>"+club.cname+"</option>")
                    }
                }
            },"json")
        })

        $(function () {
            var sf=true;
            $("form").submit(function () {
                if($("[name=pname]").val()==""){
                    alert("球员姓名不能为空！");
                    return false;
                }
                if($("[name=birthday]").val()==""){
                    alert("日期不能为空！");
                    return false;
                }
                if($("[name=height]").val()==""){
                    alert("身高不能为空！");
                    return false;
                }
                if($("[name=weight]").val()==""){
                    alert("体重不能为空！");
                    return false;
                }
                if($("[name=cid]").val()==0){
                    alert("所属球队不能为空！");
                    return false;
                }
                if(!sf){
                    return false;
                }

                var rq=/^\d{4}-\d{2}-\d{2}$/;
                var req =/^\d+$/;
                if(!rq.test($("[name=birthday]").val())){
                    alert("日期格式错误！");
                    return false;
                }else if(!req.test($("[name=height]").val())){
                    alert("日期格式错误！");
                }
            })
        })

    </script>
</head>
<body>
<div style="margin: 0px auto;width: 520px">
        <h2 style="text-align: center">添加球员信息</h2>
    <form action="/players/update" method="post">
        <table bgcolor="#faebd7" border="1">
            <tr>
                <td>球员姓名:
                    <input name="pname" th:value="${players.pname}" type="text"/>
                </td>
            </tr>
            <tr>
                <td>出生时间:
                    <input name="birthday" th:value="${players.birthday}" type="text"/>
                </td>
            </tr>
            <tr>
                <td>球员身高:
                    <input name="height" th:value="${players.height}" type="text">
                </td>
            </tr>
            <tr>
                <td>球员体重:
                    <input name="weight" th:value="${players.weight}" type="text"/>
                </td>
            </tr>
            <tr>
                <td>球员位置:
                    <input type="radio" name="position" value="控球后卫" th:checked="${players.position!=null}?${players.position=='控球后卫'}">控球后卫
                    <input type="radio" name="position" value="得分后卫" th:checked="${players.position!=null}?${players.position=='得分后卫'}">得分后卫
                    <input type="radio" name="position" value="小前锋" th:checked="${players.position!=null}?${players.position=='小前锋'}">小前锋
                    <input type="radio" name="position" value="大前锋" th:checked="${players.position!=null}?${players.position=='大前锋'}">大前锋
                    <input type="radio" name="position" value="中锋" th:checked="${players.position!=null}?${players.position=='中锋'}">中锋
                </td>
            </tr>
            <tr>
                <td>所属球队:
                <select name="cid">
                    <option value="">请选择</option>
                </select>
            </td>
            </tr>
            <tr>
                <td>相关操作:
                    <input type="submit" value="修改">
                    <a href="/players/list"><input type="button" value="返回"/></a>
                </td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>